﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StudentStatistics
{
    /// <summary>
    /// StudentAnswerControl.xaml 的交互逻辑
    /// </summary>
    public partial class StudentInfo : UserControl
    {

        public static Brush PressBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/StudentStatistics;component/Images/peoplebottomclick.png", UriKind.RelativeOrAbsolute)));

        public static Brush UnPressBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/StudentStatistics;component/Images/peoplebottom.png", UriKind.RelativeOrAbsolute)));

        public Brush RedBrush
        {
            get { return (Brush)GetValue(RedBrushProperty); }
            set { SetValue(RedBrushProperty, value); }
        }
        public static readonly DependencyProperty RedBrushProperty =
            DependencyProperty.Register("RedBrush", typeof(Brush), typeof(StudentInfo), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(255, 242, 112, 110))));

        public Brush BlueBrush
        {
            get { return (Brush)GetValue(BlueBrushProperty); }
            set { SetValue(BlueBrushProperty, value); }
        }
        public static readonly DependencyProperty BlueBrushProperty =
            DependencyProperty.Register("BlueBrush", typeof(Brush), typeof(StudentInfo), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(216, 255, 0))));

        public StudentData StudentData
        {
            get { return (StudentData)GetValue(StudentDataProperty); }
            set { SetValue(StudentDataProperty, value); }
        }
        public static readonly DependencyProperty StudentDataProperty =
            DependencyProperty.Register("StudentData", typeof(StudentData), typeof(StudentInfo), new PropertyMetadata(null));

        public StudentInfo()
        {
            InitializeComponent();
            this.Loaded += StudentInfo_Loaded;
            this.Margin = new Thickness(0, 0, -2, 0);
        }

        void StudentInfo_Loaded(object sender, RoutedEventArgs e)
        {
            if (StudentData != null)
            {
                this.StudentRightRate.Text = StudentData.Rate * 100 + "%";
                this.StuedentName.Text = StudentData.Name;
                if (StudentData.Rate >= 0.6)
                {
                    this.StudentRightRate.Foreground = this.BlueBrush;
                }
                else
                {
                    this.StudentRightRate.Foreground = this.RedBrush;
                }
                SetUnPress();
            }
        }

        Point? mousePoint = null;
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            this.viewbutton.Background = PressBrush;

            mousePoint = e.GetPosition(this);
        }

        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            base.OnPreviewMouseMove(e);
        }

        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonUp(e);

            SetUnPress();

            var point = e.GetPosition(this);
            if (mousePoint != null && Math.Abs(mousePoint.Value.X - point.X) < 10 && Math.Abs(mousePoint.Value.Y - point.Y) < 10)
            {
                //点击出现单个学生的成绩界面
                ResultsMainControl.Instacne.AddViewControl(new StudentAnswerControl(StudentData));
            }

            mousePoint = null;

        }

        public void SetUnPress()
        {
            this.viewbutton.Background = UnPressBrush;
        }

        private void viewbutton_Click(object sender, RoutedEventArgs e)
        {
            // StudentAnswerControl.StudentData = StudentData;
            //点击出现单个学生的成绩界面
            //ResultsMainControl.Instacne.AddViewControl(new StudentAnswerControl(StudentData));
        }

    }
}
